//vue.config.js
const TransformPages = require('uni-read-pages')
const {
	webpack
} = new TransformPages()
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const CompressionWebpackPlugin = require('compression-webpack-plugin');
const path = require('path'); // 引入path模块

const IP = "https://gfzc-sit.syswinsoft.com"
// const IP = "https://szzc-sit.test.cgbchina.com.cn:7571"
// const IP = "http://console.wuyetoon.com:9002/"
// const IP = "https://wxyztoon.syswinsoft.com"
// http://172.31.118.109:55433
module.exports = {
	productionSourceMap: false,
	lintOnSave: false, // 关闭eslint
	// 使用 Vue CLI 提供的 outputDir 配置输出目录
	outputDir: path.resolve(__dirname, 'dist'),
	configureWebpack: config => {
		config.plugins.push(new webpack.DefinePlugin({
			ROUTES: webpack.DefinePlugin.runtimeValue(() => {
				const tfPages = new TransformPages({
					includes: ['path', 'name', 'aliasPath', 'meta']
				});
				return JSON.stringify(tfPages.routes)
			}, true)
		}))
		if (process.env.NODE_ENV === 'production') {
			config.resolve.alias['bn.js'] = path.resolve(process.cwd(), 'node_modules', 'bn.js')

			config.optimization.splitChunks.chunks = 'all';// 对所有模块进行代码分割

			// 为生产环境修改配置...
			config.plugins.push(new BundleAnalyzerPlugin({
				analyzerMode: 'static',
				reportFilename: '111report.html',
				// openAnalyzer: false,
			}))

			config.plugins.push(new CompressionWebpackPlugin({
				filename: '[path][base].gz[query]',
				algorithm: 'gzip',
				test: /\.js$|\.html$|.\css/,
				threshold: 10240, // 只有大小大于该值的资源会被处理 10240
				minRatio: 0.8, // 只有压缩率小于这个值的资源才会被处理
				deleteOriginalAssets: false // 删除原文件
			}))

		}

	},
	devServer: {
		port: 8080,
		proxy: {
			'/usermanager': {
				target: IP,
				changeOrigin: true,
				pathRewrite: {
					'^/usermanager': ''
				}
			},
			'/apiweb': {
				target: IP,
				changeOrigin: true,
				pathRewrite: {
					'^/apiweb': ''
				}
			},
			'/customerweb': {
				target: IP,
				changeOrigin: true,
				pathRewrite: {
					'^/customerweb': ''
				}
			},
			'/open': {
				target: IP,
				changeOrigin: true,
				pathRewrite: {
					'^/open': ''
				}
			},
			'/rentownerh5': {
				target: IP,
				changeOrigin: true,
				pathRewrite: {
					'^/rentownerh5': ''
				}
			},
			'/basedata': {
				target: IP,
				changeOrigin: true,
				pathRewrite: {
					'^/basedata': ''
				}
			},
			'/message': {
				target: IP,
				changeOrigin: true,
				pathRewrite: {
					'^/message': ''
				}
			}
		},
	}
}
